#include "xml.h"
#include "file.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>

xmlDocPtr ufoXmlDocFromFile(const char* filename)
{
	xmlDocPtr doc = 0;			
	UFO_IO ioXML = 0;
	unsigned char *bufXML = 0;

	ioXML = ufoIoFromFile(filename);
	if (ioXML) {
		int nSize = ufoIoGetSize(ioXML);
		bufXML = (unsigned char*)malloc(nSize+1);
		ufoIoRead(ioXML, bufXML, nSize);
		bufXML[nSize] = 0;
		doc = xmlParseMemory((char*)bufXML, nSize);

		free(bufXML);
		ufoIoClose(ioXML);
		ioXML = 0;
	}

	return doc;
}